package com.ehome.poct.core.controller;

import com.ehome.poct.core.api.dto.check.AlgoLocalDataDTO;
import com.ehome.poct.core.api.dto.check.AlgoNotifyDTO;
import com.ehome.poct.core.api.dto.check.CheckParamDTO;
import com.ehome.poct.core.api.dto.check.project.EhomeProjectDTO;
import com.ehome.poct.core.api.virtual.CheckProjectService;
import com.ehome.poct.core.api.vo.check.CellBoardValidVO;
import com.ehome.poct.core.api.vo.check.CellCheckDataVO;
import com.ehome.poct.core.api.vo.check.CheckProcessResultVO;
import com.ehome.poct.core.api.vo.check.CheckStatusVO;
import com.ehome.poct.core.application.StandaloneCheckExe;
import com.ehome.poct.core.application.StandaloneCheckQry;
import com.ehome.web.annotation.RequestLog;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 检测控制器类
 *
 * @author cq
 * @since 2022/02/03 16: 21
 **/
@Api(tags = "检测处理")
@ApiSupport(author = "cq")
@RequestMapping("/check")
@RestController
@AllArgsConstructor
public class CheckController {
    private final StandaloneCheckExe checkCmd;
    private final StandaloneCheckQry checkQry;
    private final CheckProjectService checkProjectService;
    @ApiOperation("处理检测")
    @ApiOperationSupport(author = "cq")
    @PostMapping
    @RequestLog
    public CheckProcessResultVO doProcessCheck(@RequestBody CheckParamDTO checkParamDto) {
        return checkCmd.processCheck(checkParamDto);
    }

    @ApiOperation("查询检测状态（轮询）")
    @ApiOperationSupport(author = "cq")
    @GetMapping("/poll/status/{id}")
    @RequestLog
    public CheckStatusVO pollGetStatus(@PathVariable @ApiParam(value = "检测数据主键ID", required = true) Long id) {
        return checkCmd.pollGetStatus(id);
    }

    @ApiOperation("查询检测状态（手动）")
    @ApiOperationSupport(author = "cq")
    @GetMapping("/manual/status/{id}")
    public CheckStatusVO manualGetStatus(@PathVariable @ApiParam(value = "检测数据主键ID", required = true) Long id) {
        return checkCmd.manualGetStatus(id);
    }

    @ApiOperation("算法分析完成通知")
    @ApiOperationSupport(author = "wyc")
    @PostMapping("/algo/callBack")
    @RequestLog
    public void algoCallBack(@Valid @RequestBody AlgoNotifyDTO param){
        checkCmd.algoCallBack(param);
    }


    @ApiOperation("校验计数板是否存在")
    @ApiOperationSupport(author = "cq")
    @GetMapping("/exist/{sno}")
    public Boolean  boardIsExist(@PathVariable String sno) {
        return checkCmd.boardIsExist(sno);
    }

    @ApiOperation("校验计数板是否存在，并返回板子厚度信息")
    @ApiOperationSupport(author = "cq")
    @GetMapping("/thickness/{sno}")
    public CellBoardValidVO boardThickness(@PathVariable String sno) {
        return checkCmd.boardThickness(sno);
    }

    @ApiOperation("根据ID获取血常规数据详细")
    @ApiOperationSupport(author = "cq")
    @GetMapping("/getCellData/{id}")
    public CellCheckDataVO getCellData(@PathVariable Long id){
        return checkQry.getCellData(id);
    }

    @ApiOperation("获取检测项目")
    @GetMapping("/project/{type}")
    public List<EhomeProjectDTO> getEhomeProjectWithType(@PathVariable @ApiParam("0：所有检测类型；1：金标仪检测类型；2：血常规检测类型；3：联机检测类型") Integer type) {
        return checkProjectService.selectWithType(type);
    }

    @ApiOperation("处理检测--算法本地化结果")
    @ApiOperationSupport(author = "cq")
    @PostMapping("/savelocalalgodata")
    @RequestLog
    public CheckProcessResultVO  saveLocalAlgodata(@RequestBody AlgoLocalDataDTO algoDto) {
        return checkCmd.saveLocalAlgodata(algoDto);
    }
}
